package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.Trade;
import com.ayou.eggguard.farm.service.TradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/trade")
public class TradeController {

    @Autowired
    private TradeService tradeService;

    @GetMapping("/getRecords")
    public Result<PageBean<Trade>> getTrades(Integer pageNum,
                                             Integer pageSize,
                                             @RequestParam(required = false) String orderNumber){
        PageBean<Trade> pb= tradeService.getTrades(pageNum,pageSize,orderNumber);
        return Result.success(pb);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Trade trade){
        tradeService.add(trade);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Trade trade){
        tradeService.update(trade);
        return Result.success();
    }

    @GetMapping("/delete")
    public Result delete(Integer tradeId){
        tradeService.delete(tradeId);
        return Result.success();
    }
}
